package com.wanshi.dao;

import com.wanshi.entity.Area;
import com.wanshi.entity.Province;
import com.wanshi.entity.Shi;
import com.wanshi.utils.JDBCUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class AreaDao {

    //1 查询所有省省级行政单位
    public List<Province> getShengs() throws SQLException {
        QueryRunner runner = new QueryRunner(JDBCUtil.getSource());
        return runner.query("select * from provinces",new BeanListHandler<>(Province.class));
    }

    //2 根据省id 查所有城市
    public List<Shi> getShis(String shengId) throws SQLException {
        QueryRunner runner = new QueryRunner(JDBCUtil.getSource());
        return runner.query("select * from cities where provinceid =?",new BeanListHandler<>(Shi.class),shengId);
    }

    //3 根据城市id查询所有的 区县
    public List<Area> getXians(String cityId) throws SQLException {
        QueryRunner runner = new QueryRunner(JDBCUtil.getSource());
        return runner.query("select * from areas where cityid =?",new BeanListHandler<>(Area.class),cityId);
    }
}
